package com.dubbo.homework.impl;

import com.dubbo.homework.HelloService;
import org.apache.dubbo.config.annotation.Service;

import java.util.Random;
import java.util.concurrent.TimeUnit;

@Service
public class HelloServiceImpl implements HelloService {
    @Override
    public String sayHelloA(String message) {
        return callService("sayHelloA",message);
    }

    @Override
    public String sayHelloB(String message) {
        return callService("sayHelloB",message);
    }

    @Override
    public String sayHelloC(String message) {
        return callService("sayHelloC",message);
    }

    private String callService(String method,String message){
        int randomInt = new Random().nextInt(100);
        try {
            TimeUnit.MILLISECONDS.sleep(randomInt);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        String result = method + "->" + message;
        System.out.println(result);
        return result;
    }
}
